package com.lzlclass.intercepter;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class LoginHandleInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String l = request.getParameter("l");
        if("lanjie".equals(l)){
            System.out.println("拦截成功");
            response.setContentType("text/html;charset=UTF-8");
            response.getWriter().write("被拦截了！");
            return false;
        }
        System.out.println("拦截放行");
        return true;
    }
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("LoginHandleInterceptor：postHandle结束");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("LoginHandleInterceptor：afterCompletion结束");
    }
}